package com.example.orderassembly.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.orderassembly.service.IStorePurchaseOrderService;
import com.woniu.cloud.common.exception.TicketException;
import com.woniuxy.api.StorePurchaseOrderApi;
import com.woniu.cloud.common.dto.Result;
import com.woniuxy.entity.StorePurchaseDetailOrder;
import com.woniuxy.entity.StorePurchaseOrder;
import com.woniuxy.form.GetAfterSaleByPlatform;
import com.woniuxy.form.GetOrder;
import com.woniuxy.form.InsertStorePurchaseDetailOrder;
import com.woniuxy.form.InsertStorePurchaseOrder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 店铺进货订单表 前端控制器
 * </p>
 *
 * @author yang
 * @since 2021-09-21
 */
@RestController
@Slf4j
@SuppressWarnings("all")
public class StorePurchaseOrderController implements StorePurchaseOrderApi {
    @Resource
    IStorePurchaseOrderService storePurchaseOrderService;

    /**
     *已测
     * @param insertStorePurchaseOrder
     * @return
     */
    @PostMapping("/insertStorePurchaseOrder")
    @Override
    public Result insertStorePurchaseOrder(InsertStorePurchaseOrder insertStorePurchaseOrder) {
        log.info("增加店铺进货订单表 参数  insertStorePurchaseOrder={}",insertStorePurchaseOrder);
        if(null==insertStorePurchaseOrder){
            log.info("参数错误");
            throw  new TicketException("参数异常");
        }
        Boolean bool = storePurchaseOrderService.insertStorePurchaseOrder(insertStorePurchaseOrder);
        return bool?Result.success("新增成功",bool):Result.fail("失败",bool);
    }

    /**
     * 已测
     * @param getOrder
     * @return
     */
    @Override
    public Result getStorePurchaseOrderByStoreId(GetAfterSaleByPlatform getAfterSaleByPlatform) {
        log.info("店铺查看该店铺的进货订单表 参数 getOrder={}",getAfterSaleByPlatform);
        if(null==getAfterSaleByPlatform){
            log.info("参数错误");
            throw  new TicketException("参数异常");
        }
        IPage<StorePurchaseOrder> iPage = storePurchaseOrderService.getStorePurchaseOrderByStoreId(getAfterSaleByPlatform);
        return iPage.getRecords().size()==0?Result.fail("查询失败",iPage):Result.success("成功",iPage);
    }

    /**
     * 已测
     * @param getAfterSaleByPlatform
     * @return
     */
    @Override
    public Result getStorePurchaseOrderByPlatform(GetAfterSaleByPlatform getAfterSaleByPlatform) {
        log.info("平台分页查看所有的 进货订单表");
        if (null==getAfterSaleByPlatform){
            log.info("参数错误");
            throw  new TicketException("参数异常");
        }
        IPage<StorePurchaseOrder> iPage = storePurchaseOrderService.getStorePurchaseOrderByPlatform(getAfterSaleByPlatform);
        return iPage.getRecords().size()==0?Result.fail("查询失败",iPage):Result.success("成功",iPage);
    }

    /**
     *已测
     * @param storePurchaseOrderId
     * @param status
     * @return
     */
    @Override
    public Result updateStorePurchaseOrderByPlatform(Integer storePurchaseOrderId, Integer status) {
        log.info("平台修改进货商品订单的订单状态 参数 storePurchaseOrderId={},status={}",storePurchaseOrderId,status);
        if(null==storePurchaseOrderId||null==status){
            log.info("参数错误");
            throw  new TicketException("参数异常");
        }
        Boolean bool = storePurchaseOrderService.updateStorePurchaseOrderByPlatform(storePurchaseOrderId,status);
        return bool?Result.success("修改成功",bool):Result.fail("失败",bool);
    }

    @Override
    public Result getStorePurchaseOrderById(Integer id) {
        StorePurchaseOrder storePurchaseOrder = storePurchaseOrderService.getStorePurchaseOrderById(id);
        return Result.success("查询成功",storePurchaseOrder);
    }


}

